<?php
class BaseWelcome extends Zend_Db_Table
{   
    protected $_name = "welcome";
    
    /**
    * Class constructor
    * @return void
    */    
	function __construct($config = null){
        parent::__construct();
        
        
        $this->id = 0;
        
        $this->content_en = "";
        
        $this->content_vi = "";
        
    }
	
    function clearData()
    {
        
        $this->id = 0;
        
        $this->content_en = "";
        
        $this->content_vi = "";
        
    }
    
	/**
	All property of class
	*/
    
    /*
	* @declare   id of  Welcome
	*/
    protected $id;
    
    /*
	* @declare   content_en of  Welcome
	*/
    protected $content_en;
    
    /*
	* @declare   content_vi of  Welcome
	*/
    protected $content_vi;
    
    
    /**
        All method of Welcome
    */
    
    /**
     * @desc this method will set the value of the $id property
     * @param int  $id
     * @return void
     */
     function setId($id)
     {
        $this->id = $id;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $id property 
     * @param void
     * @return int of $id
     */
     function getId()
     {
        return  $this->id;
     } // end get function
     
    /**
     * @desc this method will set the value of the $content_en property
     * @param mediumtext  $content_en
     * @return void
     */
     function setContentEn($content_en)
     {
        $this->content_en = $content_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $content_en property 
     * @param void
     * @return mediumtext of $content_en
     */
     function getContentEn()
     {
        return  $this->content_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $content_vi property
     * @param mediumtext  $content_vi
     * @return void
     */
     function setContentVi($content_vi)
     {
        $this->content_vi = $content_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $content_vi property 
     * @param void
     * @return mediumtext of $content_vi
     */
     function getContentVi()
     {
        return  $this->content_vi;
     } // end get function
       
     
     
     /**
     * @desc this function get Welcome  by $id
     * @var int : $id 
     * @var 
     * @return Welcome object
     */
     function getById($id)
     {
          $row = $this->fetchRow("id='$id'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Welcome  by $content_en
     * @var mediumtext : $content_en 
     * @var 
     * @return Welcome object
     */
     function getByContentEn($content_en)
     {
          $row = $this->fetchRow("content_en='$content_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Welcome  by $content_vi
     * @var mediumtext : $content_vi 
     * @var 
     * @return Welcome object
     */
     function getByContentVi($content_vi)
     {
          $row = $this->fetchRow("content_vi='$content_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
       
     
     // function save ".trimplural($table)." 
     public function save($forceInsert= false)
     { 
         if( $forceInsert == true)
            return $this->insert($this->toArray());
         $update = false;
         $condition = array(); 
        
        if($this->getId())
        {
            // is update
            $update = true;
            $condition[] = "id ='". $this->getId() ."'";
        }
        
         if( $update )   // update Welcome
         {
            return $this->update($this->toArray(),implode(" and ",$condition));
         }
         else
         {
             $this->insert($this->toArray());
         }
     }
     /**
     * @desc this function get list of ".$table."
     * @var int : string $where condition, $page is current page, $rowCount is total row
     * @var 
     * @return user object
     */
     public function getListWelcome($where = null,$order = array(),$page = null ,$rowCount = null)
     {
        $select =  $this->select();
        if($where != null)
            $select->where($where);
         if($page===null)
             $select->from($this->_name);
        else
           $select->from($this->_name)->limitPage($page,$rowCount);
        $select->order($order);
        return $this->fetchAll($select);
     }     
     
     /**
     * @desc this method will import data from array 
     * @param void
     * @return array
     */
     function fromArray($array)
     {
        // import all proper ty
        
        if(isset($array["id"]))
                $this->id = $array["id"];
        
        if(isset($array["content_en"]))
                $this->content_en = $array["content_en"];
        
        if(isset($array["content_vi"]))
                $this->content_vi = $array["content_vi"];
        
        // return object
        return $this;
     } // end export function
     
     /**
     * @desc this method will export data to array 
     * @param void
     * @return array
     */
     function toArray()
     {
        // import all proper ty
        $array = array();
        
        $array["id"] = $this->id;
        
        $array["content_en"] = $this->content_en;
        
        $array["content_vi"] = $this->content_vi;
        
        // return object
        return $array;
     } // end export function
     
    function numRows($where = null)
    {
        $select = $this->_db->select();
        $select->from($this->_name, "COUNT(*)", $this->_schema);
        // the WHERE clause
        $where = (array) $where;
        foreach ($where as $key => $val) {
            // is $key an int?
            if (is_int($key)) {
                // $val is the full condition
                $select->where($val);
            } else {
                // $key is the condition with placeholder,
                // and $val is quoted into the condition              
                $select->where($key, $val);           
            }          
        }
        // return the results
        $stmt = $this->_db->query($select);
        
        $data = $stmt->fetchColumn(0);       
        return $data;  
    }              
}